package com.sen.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sen.dao.MenuDao;
import com.sen.entity.MenuEntity;
import com.sen.entity.RoleEntity;
import com.sen.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.awt.*;
import java.util.List;

@Service("menuService")
public class MenuServiceImpl extends ServiceImpl<MenuDao, MenuEntity> implements MenuService {
    @Autowired
    MenuDao menuDao;
    @Override
    public List<MenuEntity> queryListMenus() {
        List<MenuEntity> menuEntityList = menuDao.selectList(new QueryWrapper<MenuEntity>().eq("pid", 0));
        for (MenuEntity menuEntity : menuEntityList) {
            List<MenuEntity> menuEntities = menuDao.selectList(new QueryWrapper<MenuEntity>().eq("pid", menuEntity.getId()));
            menuEntity.setChildren(menuEntities);
        }
        return menuEntityList;
    }

    @Override
    public List<MenuEntity> queryMenusByRole(Integer roleId) {
        List<MenuEntity> menuEntityList = menuDao.queryMenusByRole(roleId);
        for (MenuEntity menuEntity : menuEntityList) {
            List<MenuEntity> menuEntities = menuDao.selectMenus(menuEntity.getId(),roleId);
            menuEntity.setChildren(menuEntities);
        }
        return menuEntityList;
    }

}
